package com.lkd.controller;

import cn.hutool.core.util.StrUtil;
import com.lkd.entity.Order;
import com.lkd.service.IOrderService;
import com.lkd.vo.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: OrderController
 * Package: com.lkd.controller
 * Description:
 *
 * @Author zt
 * @Create 2025/10/19 20:04
 * @Version 1.0
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/order-service/report")
@Slf4j
public class OrderController {
    private final IOrderService orderService;

    /**
     * 统计指定时间段内的订单数量
     */
    @GetMapping("/orderCount")
    public Result countOrder(String start, String end){
        Long count = orderService.lambdaQuery().between(StrUtil.isNotBlank(start) && StrUtil.isNotBlank(end), Order::getCreateTime,
                start, end).count();
        log.info("查询订单数量：{}", count);
        return Result.success(count);
    }

    /**
     * 统计指定时间段内的销售额(单位：元)
     */
    @GetMapping("/orderAmount")
    public Result countSalesAmount(String start, String end){
        Integer salesAmount = orderService.countSalesAmount(start, end);
        log.info("销售金额：{}", salesAmount + "元");
        return Result.success(salesAmount);
    }

}
